(function(){
	yanhx.addComponent("areaHandle",{
		opt:null,
		query:function(opt){
			this.opt=opt;
			if(!opt.data.callback){
				opt.data.callback=yanhx.find("areaHandle").fillProvince;
				this.province=opt.elem.find("#province");
				this.city=opt.elem.find("#city");
				this.county=opt.elem.find("#county");
			}
			opt.func(opt.data);
		},
		fillProvince:function(data){
			var t=yanhx.find("areaHandle");
			t.province.list(data,true);
		},
		clear_province:function(){
			this.county.empty();
			this.city.empty();
		},
		clear_city:function(){
			this.county.empty();
		},
		qry_city:function(elem){
			this.opt.data.callback=yanhx.find("areaHandle").fillCounty;
			this.opt.data.param.parent=elem.id.replace("l_","");
			this.opt.func(this.opt.data);
		},
		qry_province:function(elem){
			this.opt.data.callback=yanhx.find("areaHandle").fillCity;
			this.opt.data.param.parent=elem.id.replace("l_","");
			this.county.empty();
			this.opt.func(this.opt.data);
		},
		fillCity:function(data){
			yanhx.find("areaHandle").city.list(data,true);
		},
		fillCounty:function(data){
			yanhx.find("areaHandle").county.list(data,true);
		},
		single:function(){
			var ret={};
			ret['province']=this.setValue(this.province);
			ret['city']=this.setValue(this.city);
			ret['county']=this.setValue(this.county);
			yanhx.exec("myWin.callback",ret);
			yanhx.exec("myWin.closeWin");
			this.destroy();
		},
		destroy:function(){
			this.opt=null;
			this.province=null;
			this.city=null;
			this.county=null;
		},
		setValue:function(elem){
			var temp=elem.children(".check");
			if(temp.length){
				return {id:temp.attr("id").replace("l_",""),text:temp.text()};
			}
			else{
				return null;
			}
		}
	});
	yanhx.addFunc("_qryArea",function(){
		var t=$src();
		var src=t.get(0);
		if(src.tagName.toLowerCase()!="li") return;
		var pe=t.parent();
		if(t.hasClass("check")){
			t.removeClass("check");
			yanhx.exec("areaHandle.clear_"+pe.attr("id"));
			return;
		};
		pe.children(".check").removeClass("check");
		t.addClass("check");
		var id=pe.attr("id");
		yanhx.exec("areaHandle.qry_"+id,src);
	});
	yanhx.addFunc("retArea",function(){
		yanhx.exec("areaHandle.single");
	});
	yanhx.addFunc("showOrHideBlock",function(){
		var span=this.children("span");
		if(span.hasClass("blockCtrl")){
			span.removeClass("blockCtrl").addClass("hideCtrl");
			this.next().hide();
		}else{
			span.removeClass("hideCtrl").addClass("blockCtrl");
			this.next().show();
		}
	});
})();